#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=3e3+9;
const ll INF=1e18;
int n,m;
char a[maxn][maxn];
int dp[maxn][maxn];
ll ans;
int down[maxn][maxn];
signed main()
{
	freopen("star.in","r",stdin);
	freopen("star.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cin>>a[i][j];
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) down[i][j]=1;
	for(int c=1;c<=m;c++)
	{
		for(int r=n-1;r;r--)
		{
			if(a[r][c]==a[r+1][c]) down[r][c]=down[r+1][c]+1;
			else down[r][c]=1;
		}
	}
	for(int x=1;x<n;x++)
	{
		for(int y=x+1;y<=n;y++)
		{
			int h=y-x+1;
			int j=1;
			while(j<=m)
			{
				if(a[x][j]!=a[y][j]) {j++;continue;}
				char p=a[x][j];
				int k=j;
				while(k<=m&&a[x][k]==p&&a[y][k]==p) k++;
				ll cnt=0;
				for(int t=j;t<k;t++) if(down[x][t]>=h) cnt++;
				if(cnt>=2) ans+=(cnt)*(cnt-1)/2;
				j=k;
			}
		}
	}
	cout<<ans<<'\n';
	return 0;
}
